package cn.ccew.sys.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import cn.ccew.common.base.model.BaseEntity;

/**
 * @文件名称: BaseEntity.java
 * @类路径: cn.common.base
 * @描述: 组织机构树
 * @公司：春城1网
 * @作者：李兴建
 * @时间：2013-9-29 上午11:12:08
 * @版本：V1.0
 */
@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Table(name = "sys_orgnization")
public class SysOrgnization extends BaseEntity {
	/**
	 * 机构名称
	 */
	private String orgName;
	/**
	 * 机构图标地址
	 */
	private String orgImag;
	/**
	 * 是否是叶子节点，不做持久
	 */
	@Transient
	private boolean leaf;
	/**
	 * 机构一对多
	 */
	@OneToMany(mappedBy = "org")
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)  
	private Set<SysOrgnization> chileren = new HashSet<SysOrgnization>();
	/**
	 * 机构多对一 双向映射
	 */
	@ManyToOne
	@JoinColumn(name = "pid")
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)  
	private SysOrgnization org;

	public String getOrgName() {
		return orgName;
	}

	public void setOrgName(String orgName) {
		this.orgName = orgName;
	}

	public String getOrgImag() {
		return orgImag;
	}

	public void setOrgImag(String orgImag) {
		this.orgImag = orgImag;
	}

	public Set<SysOrgnization> getChileren() {
		return chileren;
	}

	public void setChileren(Set<SysOrgnization> chileren) {
		this.chileren = chileren;
	}

	public SysOrgnization getOrg() {
		return org;
	}

	public void setOrg(SysOrgnization org) {
		this.org = org;
	}

	public boolean getLeaf() {
		if (chileren.size() < 1) {
			return true;
		}
		return leaf;
	}

	public void setLeaf(boolean leaf) {
		this.leaf = leaf;
	}
}
